package test.com.spring.lo;

import com.spring.lo.dao.UserDaoImpl;
import com.spring.lo.po.User;
import com.spring.lo.service.UserServiceImpl;
import org.apache.commons.dbcp.BasicDataSource;
import org.junit.Test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Spring框架手写测试。从原始版本慢慢进化到仿照 spring管理
 * @author zhagbh
 */
public class SpringTestV1 {

    /**
     * 第一版本，纯手撸查询，不方便实现也不方便测试
     */
    @Test
    public void findUserV1() {
        UserServiceImpl userService = new UserServiceImpl();
        UserDaoImpl userDao = new UserDaoImpl();
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/spring");
        dataSource.setUsername("root");
        dataSource.setPassword("root");
        userDao.setDataSource(dataSource);
        userService.setUserDao(userDao);

        //实现用户查询功能
        Map<String, Object> map = new HashMap<>();
        map.put("username", "王五");
        List<User> users = userService.queryUsers(map);
        System.out.println(users);
    }

}
